package com.ruoyi.cbs.evaluate.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.cbs.evaluate.domain.EvaluateTemplate;
import com.ruoyi.cbs.evaluate.service.IEvaluateTemplateService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考核模板Controller
 * 
 * @author ruoyi
 * @date 2025-11-11
 */
@RestController
@RequestMapping("/evaluate/template")
public class EvaluateTemplateController extends BaseController
{
    @Autowired
    private IEvaluateTemplateService evaluateTemplateService;

    /**
     * 查询考核模板列表
     */
    @PreAuthorize("@ss.hasPermi('evaluate:template:list')")
    @GetMapping("/list")
    public TableDataInfo list(EvaluateTemplate evaluateTemplate)
    {
        startPage();
        List<EvaluateTemplate> list = evaluateTemplateService.selectEvaluateTemplateList(evaluateTemplate);
        return getDataTable(list);
    }

    /**
     * 导出考核模板列表
     */
    @PreAuthorize("@ss.hasPermi('evaluate:template:export')")
    @Log(title = "考核模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EvaluateTemplate evaluateTemplate)
    {
        List<EvaluateTemplate> list = evaluateTemplateService.selectEvaluateTemplateList(evaluateTemplate);
        ExcelUtil<EvaluateTemplate> util = new ExcelUtil<EvaluateTemplate>(EvaluateTemplate.class);
        util.exportExcel(response, list, "考核模板数据");
    }

    /**
     * 获取考核模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('evaluate:template:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(evaluateTemplateService.selectEvaluateTemplateById(id));
    }

    /**
     * 新增考核模板
     */
    @PreAuthorize("@ss.hasPermi('evaluate:template:add')")
    @Log(title = "考核模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EvaluateTemplate evaluateTemplate)
    {
        return toAjax(evaluateTemplateService.insertEvaluateTemplate(evaluateTemplate));
    }

    /**
     * 修改考核模板
     */
    @PreAuthorize("@ss.hasPermi('evaluate:template:edit')")
    @Log(title = "考核模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EvaluateTemplate evaluateTemplate)
    {
        return toAjax(evaluateTemplateService.updateEvaluateTemplate(evaluateTemplate));
    }

    /**
     * 删除考核模板
     */
    @PreAuthorize("@ss.hasPermi('evaluate:template:remove')")
    @Log(title = "考核模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(evaluateTemplateService.deleteEvaluateTemplateByIds(ids));
    }
}
